package ast;

import compiler.OutputFormatter;

public class IfStatement extends Statement {
	private Operation operation;
	private StatementList ifStatement;
	private StatementList elseStatement;
	
	public IfStatement(Operation operation, StatementList ifStatement) {
		setOperation(operation);
		setIfStatement(ifStatement);
		setElseStatement(null);
	}
	
	public IfStatement(Operation operation, StatementList ifStatement, StatementList elseStatement) {
		setOperation(operation);
		setIfStatement(ifStatement);
		setElseStatement(elseStatement);
	}	
	
	@Override
	public void genC(OutputFormatter of) {
		of.output("if");
		operation.genC(of);
		of.space();
		of.output("{");
		of.endLine();
		of.increaseIndent();
		ifStatement.genC(of);
		of.decreaseIndent();
		of.output("}");
		of.endLine();
		if(elseStatement != null) {
			of.output("else");
			of.space();
			of.output("{");
			of.endLine();
			of.increaseIndent();
			elseStatement.genC(of);
			of.decreaseIndent();
			of.output("}");
			of.endLine();			
		}
		//super.genC(of);
	}
	
	
	public Operation getComparison() {
		return operation;
	}
	public StatementList getIfStatement() {
		return ifStatement;
	}
	public StatementList getElseStatement() {
		return elseStatement;
	}
	public void setOperation(Operation operation) {
		this.operation = operation;
	}
	public void setIfStatement(StatementList ifStatement) {
		this.ifStatement = ifStatement;
	}
	public void setElseStatement(StatementList elseStatement) {
		this.elseStatement = elseStatement;
	}
	
}